package com.app.controller;

import com.app.domain.dto.R;
import com.app.service.JvmDebugService;
import com.app.service.TestService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * ceshi
 *
 * @author ch
 * @date 2022/12/8 13:29
 */
@RestController
@AllArgsConstructor
public class TestController {

    private final TestService testService;

    private final JvmDebugService jvmDebugService;

    @GetMapping("/getTest1")
    public R getTest1() throws Exception {
        Thread.sleep(3000);
        return R.code(200);
    }

    @GetMapping("/test")
    public String test(String type) throws Exception {
        return testService.executeMethod(type);
    }

    @GetMapping("/jvmDebug")
    public String jvmDebug() throws Exception {
        jvmDebugService.runLotDbConnection();
        return "jvmDebug";
    }

    @GetMapping("/jvmDebug2")
    public String jvmDebug2() throws Exception {
        jvmDebugService.runDeepMethod();
        return "jvmDebug2";
    }

    @GetMapping("/jvmDebug3")
    public String jvmDebug3() throws Exception {
        jvmDebugService.runLotThread();
        return "jvmDebug3";
    }

    @GetMapping("/jvmDebug4")
    public String jvmDebug4() throws Exception {
        jvmDebugService.runSleepMethod();
        return "jvmDebug4";
    }

    @GetMapping(value = {"/a", "/c"})
    public String duo(HttpServletRequest httpServletRequest) throws Exception {
        return httpServletRequest.getRequestURI();
    }

    @GetMapping("/b")
    public String test2() throws Exception {
        Thread.sleep(1000);
        return "b";
    }
}
